<?php

print_r($_GET);
//Trang ca nhan - Lay thong tin cua user - Lay bai viet cua user nua 
  // BAI VIET CUA USER CO 3 TRUONG HOP  
      // 1. BV MOI , 2. ALBUM , 3. BAIVIET DANG CHO DUYET - CHI CO USER THAY - KHI USER NAY LOGIN , CON KHACH THI KHONG THAY

// GET PROFILE USER -----

	if(!isset($_GET['page']) || $_GET['page']==1 || $_GET['page'] % LOAD_TIME == 0){
		
	$data1['title']=web_title($_GET['u'],'user');
	$u=$_GET['u'];
	$c=new cache;
	
	$data['user']=cache_get_user($u);
	


	if(!$data['user']){
			$data['error'][]='User này không tồn tại, xin vui lòng kiểm tra lại !';
	}
	
	if(isset($_GET['ext'])){
		switch($_GET['ext']){
		case "status":
			
			$sql ="select id,cat_id,post_id,username,id_album ,is_image,is_video,is_text from index_post where username='".mysql_real_escape_string($u)."'  and status=0  order by id desc";
			$sql2="select id from index_post where username='".mysql_real_escape_string($u)."' and status=0";
			$pager = new Pagination($sql,LOAD_ITEMS,4,"",300,"post");
			break;
			
		case "album":
			$sql ="select * from album where username='".mysql_real_escape_string($u)."' order by id desc";
			$sql2="select * from album where username='".mysql_real_escape_string($u)."'";

			$pager = new Pagination($sql,LOAD_ITEMS,4,"",300,'album');
			break;
		case "picture":
			$sql ="select id,cat_id,post_id,username,id_album ,is_image,is_video,is_text from index_post where username='".mysql_real_escape_string($u)."'  and status=1 and is_image=1  order by id desc";
			$sql2="select id from index_post where username='".mysql_real_escape_string($u)."' and status=1 and is_image=1";
			$pager = new Pagination($sql,LOAD_ITEMS,4,"",300,"post");
			
		break;
		case "video":
			$sql ="select id,cat_id,post_id,username,id_album ,is_image,is_video,is_text from index_post where username='".mysql_real_escape_string($u)."'  and status=1 and is_video=1  order by id desc";
			$sql2="select id from index_post where username='".mysql_real_escape_string($u)."' and status=1 and is_video=1";
			$pager = new Pagination($sql,LOAD_ITEMS,4,"",300,"post");
			
		break;
		case "text":
		$sql ="select id,cat_id,post_id,username,id_album ,is_image,is_video,is_text from index_post where username='".mysql_real_escape_string($u)."'  and status=1 and is_text=1  order by id desc";
			$sql2="select id from index_post where username='".mysql_real_escape_string($u)."' and status=1 and is_text=1";
			$pager = new Pagination($sql,LOAD_ITEMS,4,"",300,"post");
			
		break;	
			
		}
	}else{
			$sql ="select id,cat_id,post_id,username,id_album ,is_image,is_video,is_text from index_post where username='".mysql_real_escape_string($u)."'    order by id desc";
			$sql2="select id from index_post where username='".mysql_real_escape_string($u)."'";
			$pager = new Pagination($sql,LOAD_ITEMS,4,"",300,"post");
	
	}
	// GET BAI VIET MAC DINH CUA USER ---
echo mysql_error();

	$data[info] = $pager->paginate($c,$sql2);
	$data[nav]	= $pager->renderFullNav();
	$data['page']=$pager->get_num_page();
	
	if($_GET['ext']!='album'){
	$_SESSION['load']['query']=$sql;
	$_SESSION['load']['tpage']=$data['page'];
	}
	

	loadview('template/header',$data1);
	loadview('user/profile',$data);
	}else{
		exit();
	
	
	
	}